package cn.edu.hnnu.a.rentacar.dao.hibernateimpl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import cn.edu.hnnu.a.rentacar.beans.Customer;
import cn.edu.hnnu.a.rentacar.idao.ICustomerDAO;
import cn.edu.hnnu.a.rentacar.util.HibernateUtil;

public class CustomerDAOHibernateImpl implements ICustomerDAO {

	private static CustomerDAOHibernateImpl instance;

	private CustomerDAOHibernateImpl() {

	}

	public static CustomerDAOHibernateImpl getInstance() {
		if (null == instance) {
			instance = new CustomerDAOHibernateImpl();
		}
		return instance;
	}

	@Override
	public void addCustomer(Customer customer) {
		SessionFactory factory = HibernateUtil.getSessionFactory();
		Session session = factory.openSession();
		Transaction tran = session.beginTransaction();
		session.save(customer);
		tran.commit();
		session.close();
	}

}
